﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web;
using NewLife.Web;

namespace BingZi.HY.Core
{
    /// <summary>
    /// 页面基类(检测页面的参数之类的)
    /// </summary>
    public class BasePage :Page
    {

   

        #region "计算页面执行的时间"
        /// <summary>
        /// 计算页面执行的时间
        /// </summary>
        /// <param name="TimeStart">开始时间</param>
        public String InitTimeSpan(DateTime TimeStart)
        {
            //查询数据库所花的时间
            System.DateTime endTime = System.DateTime.Now;
            System.TimeSpan ts = endTime - TimeStart;
            String RunTime = string.Format("{0}秒{1}毫秒", ts.Seconds, ts.Milliseconds);
            TimeStart = endTime = System.DateTime.Now;
            return RunTime;
        }
        #endregion

        #region "浏览用户属性(用户页面)"

        /// <summary>
        /// 传入-用户名
        /// </summary>
        public String Web_UserName = WebHelper.GetStringParam(HttpContext.Current.Request, "UserName", "");


        private sys_UserTable _Web_UserInfo = new sys_UserTable();
        /// <summary>
        /// 传入-用户信息
        /// </summary>
        public sys_UserTable Web_UserInfo
        {
            get {
                if ((_Web_UserInfo == null || _Web_UserInfo.UserID == 0) && !String.IsNullOrEmpty(Web_UserName))
                {
                     _Web_UserInfo = sys_UserTable.FindByUserName(Web_UserName);
                }
                return _Web_UserInfo; }
        }



        private Int32 _Web_UserID = -1;
        /// <summary>
        /// 传入-用户编号
        /// </summary>
        public Int32 Web_UserID
        {
            get {
                if (_Web_UserID == -1)
                {
                    _Web_UserID = _Web_UserInfo.UserID;
                }
                return _Web_UserID; }
        }
         




        #endregion


        #region "登录用户属性"


        /// <summary>
        /// 获取登录用户编号
        /// </summary>
        public Int32 Get_UserID
        {
            get { return Common.Get_UserID; }
        }

        private String _UserName = String.Empty;
        /// <summary>
        /// 获取登录用户名
        /// </summary>
        public String Get_UserName
        {
            get
            {
                if (String.IsNullOrEmpty(_UserName) && Get_IsLogin)
                {
                    _UserInfo = Get_UserInfo;
                    if (_UserInfo != null && _UserInfo.UserID > 0)
                    {
                        _UserName = _UserInfo.U_LoginName;
                    }
                }
                return _UserName;
            }
        }

        private sys_UserTable _UserInfo = new sys_UserTable();
        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        public sys_UserTable Get_UserInfo
        {
            get
            {
                if ((_UserInfo == null || _UserInfo.UserID == 0) && Get_IsLogin)
                {
                    _UserInfo = Common.Get_UserInfo;
                }
                return _UserInfo;
            }
        }

        /// <summary>
        /// 获取登录用户是否登录
        /// </summary>
        public Boolean Get_IsLogin
        {
            get { return Get_UserID > 0; }
        }

        #endregion


    }
}
